from flask import Flask, session, redirect, url_for, request
from markupsafe import escape

app = Flask(__name__)
app.secret_key = b'joaef8(*#(#*YFKDHFIS'

@app.route('/')
def index():
    if 'username' in session:
        return 'Logged in as %s' % escape(session['username'])
    return 'not login'

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        session['username'] = request.form['username']
        app.logger.info("----" + session['username'])
        return redirect(url_for('index'))
    else:
        return '''
           <form method="post">
        <p><input type=text name=username></p>
        <p><input type=submit value=Login></p>
            </form>
        '''
@app.route('/logout')
def logout():
    session.pop('username', None)
    return redirect(url_for('index'))

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000, debug=True)